package com.sayimo.maker.commons.utils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.sayimo.uploadfile.util.UploadFileResult;

public class Base64Utils {

	public static UploadFileResult uploadByBase64(String url, String fileBase64, String fileName, String filePath,
			String imagePath) throws JsonParseException, JsonMappingException, IOException {
		Map<String, String> paramsMap = new HashMap<>();
		paramsMap.put("fileBase64", fileBase64);
		paramsMap.put("fileName", fileName);
		paramsMap.put("filePath", filePath);
		paramsMap.put("imagePath", imagePath);
		String result = HttpUtils.URLPost(url, paramsMap, "UTF-8");
		UploadFileResult f= JSONUtil.readValueToBean(result, UploadFileResult.class) ;
		return f;
	}
	/**
	 * @Package com.sayimo.maker.commons.utils
	 * @Author 谭新
	 * @MethodName: decodeBase64
	 * @Description:解密
	 * @return String
	 * @throws Exception
	 * @Date 2017年3月27日,上午9:47:45
	 */
	public static String decodeBase64(String arg) throws Exception{
		return new String(Base64.decodeBase64(arg.getBytes("UTF-8")));
	}

	public static void main(String[] args) throws MalformedURLException, IOException {
		String url = "http://testapi.sayimo.cn/schoolapi/pre/cancelorder";
		Map<String, String> paramsMap = new HashMap<>();
		paramsMap.put("orderId", "217");
		String result = HttpUtils.postMethod_URLForm(url, paramsMap);
		System.out.println(result);
	}
}
